package org.csu.pet_store_back.web;

import jakarta.annotation.Resource;
import org.csu.pet_store_back.common.CommonResponse;
import org.csu.pet_store_back.domain.Product;
import org.csu.pet_store_back.service.CatalogService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;


@RestController
@Validated
public class CatalogController {
    @Resource
    private CatalogService catalogService;

    @GetMapping("/showProductList")
    public CommonResponse<List<Product>> showProductList(@RequestParam("category") String categoryId){
        CommonResponse<List<Product>> result2=catalogService.getProductList(categoryId);
        return result2;
    }

    @PostMapping("/getProduct")
    public CommonResponse<Map> getProduct(@RequestParam("productId") String productId) throws SQLException, IOException {
        CommonResponse<Map> result=catalogService.getProduct(productId);
        return result;
    }

    @GetMapping("/searchProduct")
    public CommonResponse<List<Product>> searchProductList(@RequestParam("searchContent") String searchContent){
        CommonResponse<List<Product>> result=catalogService.searchProductList(searchContent);
        return result;
    }

}
